<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class MY_Form_validation extends CI_Form_validation 
{

	public function __construct($rules = array())
	{
		parent::__construct($rules);
		$this->CI->lang->load('MY_form_validation');
	}
	
	public function alpha_dash_space($str)
	{
		return ( ! preg_match("/^([-a-z0-9_ ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function alpha_space($str)
	{
		return ( ! preg_match("/^([a-z ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function alphanum_space($str)
	{
		return ( ! preg_match("/^([a-z0-9 ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function text_all($str)
	{
		return ( ! preg_match("/^([-a-z0-9_#,.!& ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function enumeration($str)
	{
		return ( ! preg_match("/^([a-z0-9, ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function check_student_nationality()
	{
		if(strtolower($this->CI->input->post('child_nationality')) !== 'filipino')
		{
			if($this->CI->input->post('nationality_ssp_number') AND 
			   $this->CI->input->post('nationality_visa_status') AND
			   $this->CI->input->post('nationality_auth_stay') AND
			   $this->CI->input->post('nationality_passport_no') AND
			   $this->CI->input->post('nationality_icard_no') AND
			   $this->CI->input->post('nationality_date_issued')
			  )
			  {
				return TRUE;
			  }else{
				return FALSE;
			  }
		}else{
			return TRUE;
		}
	}
	
	public function error_count()
    {
        return count($this->_error_array);
    }
	
	public function error_exists($fields)
	{
		$error_number = 0;
		foreach($fields as $k => $v):
			if(!empty($this->_field_data[$v]['error'])):
				$error_number++;
			endif;
		endforeach;
		return $error_number;
	}
 }